package com.admin.monmon.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author caixiaofeng
 * @version 1.0
 * @Description: <<>>
 * @company cxf
 * @create 2021-01-31 22:58
 */
@ApiModel("响应实体类")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class AjaxResponse {
    //是否成功
    @ApiModelProperty("是否成功")
    private boolean success;
    //状态码
    @ApiModelProperty("状态码")
    private Integer code;
    //信息
    @ApiModelProperty("信息")
    private String message;
    //数据
    @ApiModelProperty("响应实体")
    private Object data;
    public AjaxResponse(boolean success, Integer code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }
    /**
     * 返回成功
     * @return
     */
    public static AjaxResponse success(){
        AjaxResponse response = new AjaxResponse();
        response.setSuccess(true);
        response.setCode(StatusCode.SUCCESS);
        response.setMessage("success");
        return response;
    }
    /**
     * 返回成功
     * @return
     */
    public static AjaxResponse success(String message){
        AjaxResponse response = new AjaxResponse();
        response.setSuccess(true);
        response.setCode(StatusCode.SUCCESS);
        response.setMessage(message);
        return response;
    }
    /**
     * 返回成功
     * @param data 数据
     * @return
     */
    public static AjaxResponse success(Object data){
        AjaxResponse response = new AjaxResponse();
        response.setSuccess(true);
        response.setCode(StatusCode.SUCCESS);
        response.setMessage("success");
        response.setData(data);
        return response;
    }
    /**
     * 返回成功
     * @param data 数据
     * @return
     */
    public static AjaxResponse success(String message,Object data){
        AjaxResponse response = new AjaxResponse();
        response.setSuccess(true);
        response.setCode(StatusCode.SUCCESS);
        response.setMessage(message);
        response.setData(data);
        return response;
    }
    /**
     * 返回失败
     * @return
     */
    public static AjaxResponse error(){
        AjaxResponse response = new AjaxResponse();
        response.setSuccess(false);
        response.setCode(StatusCode.FAILURE);
        response.setMessage("error");
        return response;
    }
    /**
     * 返回失败
     * @param data 数据
     * @return
     */
    public static AjaxResponse error(Object data){
        AjaxResponse response = new AjaxResponse();
        response.setSuccess(false);
        response.setCode(StatusCode.FAILURE);
        response.setMessage("error");
        response.setData(data);
        return response;
    }
    /**
     * 返回失败
     * @param message 信息
     * @return
     */
    public static AjaxResponse error(String message){
        AjaxResponse response = new AjaxResponse();
        response.setSuccess(false);
        response.setCode(StatusCode.FAILURE);
        response.setMessage(message);
        return response;
    }
    /**
     * 返回失败
     * @param data 数据
     * @return
     */
    public static AjaxResponse error(String message,Object data){
        AjaxResponse response = new AjaxResponse();
        response.setSuccess(false);
        response.setCode(StatusCode.FAILURE);
        response.setMessage(message);
        response.setData(data);
        return response;
    }
    /**
     * 返回失败
     * @param message 信息
     * @return
     */
    public static AjaxResponse error(String message,Integer code){
        AjaxResponse response = new AjaxResponse();
        response.setSuccess(false);
        response.setCode(code);
        response.setMessage(message);
        return response;
    }
}
